<template>
  <view class="sora-container">
    <!-- 顶部导航 -->
    <view class="top-nav">
      <view class="nav-left">
        <view class="logo-wrapper">
          <text class="logo-icon">🎬</text>
          <view class="logo-text-wrapper">
            <text class="logo-text">CSora2</text>
            <text class="logo-sub">AI Video Creator</text>
          </view>
        </view>
      </view>
      <view class="nav-right">
        <view class="nav-icon-btn" @click="goToList">
          <text class="icon">&#xf03a;</text>
        </view>
        <view class="nav-icon-btn logout" @click="confirmLogout">
          <text class="icon">&#xf011;</text>
        </view>
      </view>
    </view>

    <!-- 主标题区域 -->
    <view class="hero-section">
      <view class="hero-title">
        <text class="title-main">创造无限可能</text>
        <text class="title-sub">Sora2 AI 驱动的视频生成</text>
      </view>
      <view class="hero-stats">
        <view class="stat-item">
          <text class="stat-number">{{ stats.total }}</text>
          <text class="stat-label">总生成数</text>
        </view>
        <view class="stat-item">
          <text class="stat-number">{{ stats.success }}</text>
          <text class="stat-label">成功作品</text>
        </view>
        <view class="stat-item">
          <text class="stat-number">{{ stats.online }}</text>
          <text class="stat-label">进行中</text>
        </view>
      </view>
    </view>

    <!-- 积分板块 -->
    <view class="integral-section" @click="goToIntegral">
      <view class="integral-card">
        <view class="integral-bg-circle"></view>
        <view class="integral-bg-circle-2"></view>
        <view class="integral-content">
          <view class="integral-icon-wrapper">
            <text class="integral-icon">&#xf155;</text>
          </view>
          <view class="integral-info">
            <text class="integral-label">我的积分</text>
            <text class="integral-value">{{
              userInfo.account_integral?.balance || 0
            }}</text>
            <text class="integral-hint">点击查看积分明细 ></text>
          </view>
        </view>
        <view class="integral-shine"></view>
      </view>
    </view>

    <!-- 创作区域 -->
    <view class="create-section">
      <view class="section-title">
        <text class="icon">&#xf0ac;</text>
        <text>开始创作</text>
      </view>

      <!-- Prompt 输入框 -->
      <view class="prompt-card">
        <view class="card-header">
          <text class="icon">&#xf040;</text>
          <text>描述你的视频</text>
        </view>
        <textarea
          v-model="prompt"
          class="prompt-input"
          placeholder="详细描述你想要创建的视频场景...&#10;&#10;例如：一个美丽的日落场景，海浪轻轻拍打着沙滩，天空中飘着橙红色的云彩，一只海鸥在空中飞翔..."
          :maxlength="4000"
          :show-confirm-bar="false"
        />
        <view class="prompt-footer">
          <text class="char-count">{{ prompt.length }} / 4000</text>
          <view class="quick-prompts" @click="showPromptTemplates">
            <text class="icon">&#xf0eb;</text>
            <text>快速提示词</text>
          </view>
        </view>
      </view>

      <!-- 参考图片 -->
      <view class="reference-card">
        <view class="card-header">
          <text class="icon">&#xf03e;</text>
          <text>参考图片（可选）</text>
        </view>
        <view class="image-upload-area">
          <view
            v-for="(img, index) in referImages"
            :key="index"
            class="image-item"
          >
            <image :src="img" mode="aspectFill" class="preview-image" />
            <view class="image-delete" @click="removeImage(index)">
              <text class="icon">&#xf00d;</text>
            </view>
          </view>
          <view
            v-if="referImages.length < 3"
            class="image-upload-btn"
            @click="uploadImage"
          >
            <text class="icon">&#xf067;</text>
            <text class="upload-text">添加图片</text>
          </view>
        </view>
        <view class="image-tips">
          <text class="icon">&#xf05a;</text>
          <text>最多3张，不可包含人脸或品牌Logo</text>
        </view>
      </view>

      <!-- 模型选择 -->
      <view class="options-card">
        <view class="card-header">
          <text class="icon">&#xf013;</text>
          <text>生成设置</text>
        </view>

        <!-- 模型选择 -->
        <view class="option-group">
          <view class="option-label">
            <text class="label-text">视频模型</text>
            <text class="label-desc">{{
              model === "sora-2" ? "标准模式 720×1280" : "高清模式 1024×1792"
            }}</text>
          </view>
          <view class="option-buttons">
            <view
              class="option-btn"
              :class="{ active: model === 'sora-2' }"
              @click="model = 'sora-2'"
            >
              <text class="btn-icon">&#xf008;</text>
              <text>标准模式</text>
            </view>
            <view
              class="option-btn"
              :class="{ active: model === 'sora-2-pro' }"
              @click="model = 'sora-2-pro'"
            >
              <text class="btn-icon">&#xf144;</text>
              <text>高清模式</text>
            </view>
          </view>
        </view>

        <!-- 横屏竖屏 -->
        <view class="option-group">
          <view class="option-label">
            <text class="label-text">视频方向</text>
            <text class="label-desc">{{
              orientation === "portrait"
                ? "竖屏 适合手机浏览"
                : "横屏 适合电脑浏览"
            }}</text>
          </view>
          <view class="option-buttons">
            <view
              class="option-btn"
              :class="{ active: orientation === 'portrait' }"
              @click="orientation = 'portrait'"
            >
              <text class="btn-icon">&#xf10b;</text>
              <text>竖屏</text>
            </view>
            <view
              class="option-btn"
              :class="{ active: orientation === 'landscape' }"
              @click="orientation = 'landscape'"
            >
              <text class="btn-icon">&#xf10c;</text>
              <text>横屏</text>
            </view>
          </view>
        </view>

        <!-- 时长选择 -->
        <view class="option-group" v-if="model === 'sora-2-pro'">
          <view class="option-label">
            <text class="label-text">视频时长</text>
            <text class="label-desc">高清模式支持自定义时长</text>
          </view>
          <view class="option-buttons">
            <view
              class="option-btn"
              :class="{ active: duration === 10 }"
              @click="duration = 10"
            >
              <text class="btn-icon">&#xf017;</text>
              <text>10秒</text>
            </view>
            <view
              class="option-btn"
              :class="{ active: duration === 15 }"
              @click="duration = 15"
            >
              <text class="btn-icon">&#xf017;</text>
              <text>15秒</text>
            </view>
          </view>
        </view>

        <view class="option-tips" v-if="model === 'sora-2'">
          <text class="icon">&#xf05a;</text>
          <text>标准模式时长固定为10秒，切换到高清模式可选择15秒</text>
        </view>
      </view>

      <!-- 生成按钮 -->
      <view class="generate-section">
        <button
          class="generate-btn"
          :class="{ loading: isGenerating, disabled: !canGenerate }"
          :disabled="!canGenerate"
          @click="confirmGenerate"
        >
          <text v-if="!isGenerating" class="btn-icon">&#xf04b;</text>
          <text v-else class="btn-icon spinning">&#xf110;</text>
          <text class="btn-text">{{
            isGenerating ? "生成中..." : "开始生成"
          }}</text>
        </button>
        <view class="generate-tips-wrapper">
          <text class="generate-tips">预计耗时 30-120 秒</text>
          <view class="integral-cost-tip">
            <text class="icon">&#xf155;</text>
            <text>消耗 {{ integralCost }} 积分</text>
          </view>
        </view>
      </view>
    </view>

    <!-- 最近作品 -->
    <view class="recent-section" v-if="recentWorks.length > 0">
      <view class="section-title">
        <text class="icon">&#xf1da;</text>
        <text>最近作品</text>
        <text class="view-all" @click="goToList">查看全部 ></text>
      </view>
      <scroll-view scroll-x class="recent-scroll">
        <view
          v-for="work in recentWorks"
          :key="work.jobId"
          class="work-card"
          @click="viewWork(work)"
        >
          <view class="work-cover">
            <image
              v-if="work.status === 'SUCCESS' && work.videoUrl"
              :src="
                work.videoUrl + '?x-oss-process=video/snapshot,t_1000,m_fast'
              "
              mode="aspectFill"
            />
            <view v-else class="work-placeholder">
              <text class="icon spinning">&#xf110;</text>
            </view>
            <view class="work-status" :class="work.status.toLowerCase()">
              <text>{{ formatStatus(work.status) }}</text>
            </view>
          </view>
          <view class="work-info">
            <text class="work-prompt">{{ work.prompt }}</text>
            <text class="work-time">{{ formatTime(work._add_time) }}</text>
          </view>
        </view>
      </scroll-view>
    </view>

    <!-- 积分不足对话框 -->
    <view
      v-if="showInsufficientDialog"
      class="alert-modal"
      @click="showInsufficientDialog = false"
    >
      <view class="alert-dialog" @click.stop>
        <view class="alert-icon-wrapper error">
          <view class="alert-icon-bg"></view>
          <text class="alert-icon">&#xf071;</text>
        </view>
        <text class="alert-title">积分不足</text>
        <text class="alert-message">{{ insufficientMessage }}</text>
        <view class="alert-actions">
          <button class="alert-btn secondary" @click="handleInsufficientClose">
            <text>稍后再说</text>
          </button>
          <button class="alert-btn primary" @click="goToRecharge">
            <text class="btn-icon">&#xf09d;</text>
            <text>立即充值</text>
          </button>
        </view>
      </view>
    </view>

    <!-- 生成确认对话框 -->
    <view
      v-if="showConfirmDialog"
      class="confirm-modal"
      @click="showConfirmDialog = false"
    >
      <view class="confirm-dialog" @click.stop>
        <view class="confirm-icon-wrapper">
          <view class="confirm-icon-bg"></view>
          <text class="confirm-icon">&#xf155;</text>
        </view>
        <text class="confirm-title">确认生成视频</text>
        <view class="confirm-content">
          <view class="integral-info-row">
            <text class="info-label">当前积分</text>
            <text class="info-value current">{{
              userInfo.account_integral?.balance || 0
            }}</text>
          </view>
          <view class="integral-divider">
            <text class="divider-icon">&#xf063;</text>
          </view>
          <view class="integral-info-row">
            <text class="info-label"
              >消耗积分 ({{
                model === "sora-2" ? "标准模式" : "高清模式"
              }})</text
            >
            <text class="info-value cost">-{{ integralCost }}</text>
          </view>
          <view class="integral-info-row remain">
            <text class="info-label">剩余积分</text>
            <text class="info-value">{{
              (userInfo.account_integral?.balance || 0) - integralCost
            }}</text>
          </view>
        </view>
        <view class="confirm-actions">
          <button class="confirm-btn cancel" @click="showConfirmDialog = false">
            <text>取消</text>
          </button>
          <button class="confirm-btn confirm" @click="handleConfirmGenerate">
            <text class="btn-icon">&#xf04b;</text>
            <text>确认生成</text>
          </button>
        </view>
      </view>
    </view>

    <!-- 退出登录确认对话框 -->
    <view
      v-if="showLogoutDialog"
      class="confirm-modal"
      @click="showLogoutDialog = false"
    >
      <view class="confirm-dialog logout-dialog" @click.stop>
        <view class="confirm-icon-wrapper">
          <view class="confirm-icon-bg logout-bg"></view>
          <text class="confirm-icon logout-icon">&#xf08b;</text>
        </view>
        <text class="confirm-title">确认退出登录</text>
        <text class="logout-message">退出后需要重新登录才能继续使用</text>
        <view class="confirm-actions">
          <button class="confirm-btn cancel" @click="showLogoutDialog = false">
            <text>取消</text>
          </button>
          <button
            class="confirm-btn confirm logout-confirm"
            @click="handleLogout"
          >
            <text class="btn-icon">&#xf08b;</text>
            <text>确认退出</text>
          </button>
        </view>
      </view>
    </view>

    <!-- 快速提示词弹窗 -->
    <view
      v-if="showTemplates"
      class="template-modal"
      @click="showTemplates = false"
    >
      <view class="modal-content" @click.stop>
        <view class="modal-header">
          <text class="modal-title">快速提示词</text>
          <text class="modal-close" @click="showTemplates = false"
            >&#xf00d;</text
          >
        </view>
        <scroll-view scroll-y class="template-list">
          <view
            v-for="(template, index) in promptTemplates"
            :key="index"
            class="template-item"
            @click="useTemplate(template)"
          >
            <text class="template-icon">{{ template.icon }}</text>
            <view class="template-info">
              <text class="template-name">{{ template.name }}</text>
              <text class="template-desc">{{ template.prompt }}</text>
            </view>
          </view>
        </scroll-view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      prompt: "",
      referImages: [],
      model: "sora-2", // 默认标准模式
      orientation: "portrait", // 默认竖屏
      duration: 15, // 默认15秒
      isGenerating: false,
      showTemplates: false,
      showConfirmDialog: false,
      showInsufficientDialog: false,
      showLogoutDialog: false,
      insufficientMessage: "",
      userInfo: {},
      stats: {
        total: 0,
        success: 0,
        online: 0,
      },
      recentWorks: [],
      promptTemplates: [
        {
          icon: "🌅",
          name: "日落海景",
          prompt:
            "一个美丽的日落场景，海浪轻轻拍打着沙滩，天空中飘着橙红色的云彩，一只海鸥在空中飞翔，温暖的光线洒在海面上",
        },
        {
          icon: "🏔️",
          name: "雪山风光",
          prompt:
            "壮丽的雪山景色，白雪覆盖的山峰在蓝天下闪耀，清澈的湖水倒映着雪山，微风吹过湖面泛起涟漪",
        },
        {
          icon: "🌆",
          name: "城市夜景",
          prompt:
            "现代化都市的夜景，高楼大厦的灯光璀璨，街道上车流如织，霓虹灯闪烁，展现出城市的繁华与活力",
        },
        {
          icon: "🌸",
          name: "春日花园",
          prompt:
            "春天的花园，樱花盛开，粉色的花瓣随风飘落，蝴蝶在花丛中飞舞，阳光透过树叶洒下斑驳的光影",
        },
        {
          icon: "🚀",
          name: "科幻未来",
          prompt:
            "未来科技城市，飞行器在高楼间穿梭，全息投影广告闪烁，机器人在街道上行走，充满科幻感的场景",
        },
        {
          icon: "🎨",
          name: "艺术抽象",
          prompt:
            "抽象艺术场景，色彩斑斓的几何图形在空间中流动变换，光影交织，营造出梦幻般的视觉效果",
        },
      ],
    };
  },
  computed: {
    canGenerate() {
      return this.prompt.trim().length >= 10 && !this.isGenerating;
    },
    // 根据模型和用户计算积分消耗
    integralCost() {
      // 特殊用户列表（高清模式固定消耗200积分）
      const SPECIAL_USERS = [
        "68e9d2f9a09a9b19e314a1d8",
        "68e9f6a6a7c432f44b2ef2b8",
        "68ea02eb99c6240906e4e24f",
        "68ea04c509664cbe6f12ac7f",
      ];

      const currentUid = this.userInfo._id;

      // 特殊用户使用高清模式时消耗200积分
      if (SPECIAL_USERS.includes(currentUid) && this.model === "sora-2-pro") {
        return 200;
      }

      // 普通用户或标准模式
      return this.model === "sora-2" ? 20 : 100;
    },
  },
  onLoad() {
    this.loadUserInfo();
    this.loadStats();
    this.loadRecentWorks();
  },
  onShow() {
    this.loadUserInfo();
    this.loadRecentWorks();
  },
  methods: {
    // 加载用户信息
    async loadUserInfo() {
      try {
        const res = await vk.callFunction({
          url: "client/user.getMyInfo",
          data: {},
        });
        if (res.code === 0) {
          this.userInfo = res.userInfo || {};
        }
      } catch (error) {
        console.error("加载用户信息失败:", error);
      }
    },

    // 加载统计数据
    async loadStats() {
      try {
        const res = await vk.callFunction({
          url: "client/sora/kh/getTaskList",
          data: {
            pageIndex: 1,
            pageSize: -1,
          },
        });
        if (res.code === 0) {
          this.stats.total = res.total || 0;
          // 获取成功数量
          const successRes = await vk.callFunction({
            url: "client/sora/kh/getTaskList",
            data: {
              pageIndex: 1,
              pageSize: -1,
              status: "SUCCESS",
            },
          });
          this.stats.success = successRes.total || 0;
          // 获取进行中数量
          const onlineRes = await vk.callFunction({
            url: "client/sora/kh/getTaskList",
            data: {
              pageIndex: 1,
              pageSize: -1,
              status: "ON_QUEUE",
            },
          });
          this.stats.online = onlineRes.total || 0;
        }
      } catch (error) {
        console.error("加载统计数据失败:", error);
      }
    },

    // 加载最近作品
    async loadRecentWorks() {
      try {
        const res = await vk.callFunction({
          url: "client/sora/kh/getTaskList",
          data: {
            pageIndex: 1,
            pageSize: 10, // 多获取一些，因为要过滤失败的
          },
        });
        if (res.code === 0) {
          // 过滤掉失败的作品，只显示成功和进行中的
          this.recentWorks = (res.rows || [])
            .filter((work) => work.status !== "FAILED")
            .slice(0, 6); // 最多显示6个
        }
      } catch (error) {
        console.error("加载最近作品失败:", error);
      }
    },

    // 上传图片
    uploadImage() {
      const maxCount = 3 - this.referImages.length;
      if (maxCount <= 0) {
        uni.showToast({
          title: "最多只能上传3张图片",
          icon: "none",
        });
        return;
      }

      uni.chooseImage({
        count: maxCount,
        sizeType: ["compressed"],
        sourceType: ["album", "camera"],
        success: (res) => {
          // 循环上传每张图片
          const totalCount = res.tempFiles.length;
          let uploadedCount = 0;

          res.tempFiles.forEach((file, index) => {
            vk.uploadFile({
              title: `上传中(${index + 1}/${totalCount})...`,
              file: file,
              success: (uploadRes) => {
                // 上传成功，将URL添加到数组
                this.referImages.push(uploadRes.url);
                console.log("图片上传成功:", uploadRes.url);

                uploadedCount++;

                // 所有图片上传完成时提示
                if (uploadedCount === totalCount) {
                  uni.showToast({
                    title: "上传成功",
                    icon: "success",
                  });
                }
              },
              fail: (err) => {
                // 上传失败
                console.error("图片上传失败:", err);
                uni.showToast({
                  title: "上传失败，请重试",
                  icon: "none",
                });
              },
            });
          });
        },
        fail: (err) => {
          console.error("选择图片失败:", err);
        },
      });
    },

    // 删除图片
    removeImage(index) {
      this.referImages.splice(index, 1);
    },

    // 显示提示词模板
    showPromptTemplates() {
      this.showTemplates = true;
    },

    // 使用模板
    useTemplate(template) {
      this.prompt = template.prompt;
      this.showTemplates = false;
    },

    // 确认生成
    confirmGenerate() {
      if (!this.canGenerate) return;

      const currentIntegral = this.userInfo.account_integral?.balance || 0;
      const costIntegral = this.integralCost;

      // 检查积分是否足够
      if (currentIntegral < costIntegral) {
        const needed = costIntegral - currentIntegral;
        const modelName = this.model === "sora-2" ? "标准模式" : "高清模式";
        this.insufficientMessage = `当前积分：${currentIntegral}\n生成视频需要：${costIntegral} 积分 (${modelName})\n还需要：${needed} 积分\n\n立即充值即可获得更多积分`;
        this.showInsufficientDialog = true;
        return;
      }

      // 显示自定义确认对话框
      this.showConfirmDialog = true;
    },

    // 处理确认生成
    handleConfirmGenerate() {
      this.showConfirmDialog = false;
      this.generateVideo();
    },

    // 关闭积分不足对话框
    handleInsufficientClose() {
      this.showInsufficientDialog = false;
      this.insufficientMessage = "";
    },

    // 生成视频
    async generateVideo() {
      if (!this.canGenerate) return;

      this.isGenerating = true;

      try {
        const data = {
          model: this.model,
          prompt: this.prompt,
          orientation: this.orientation,
        };

        // 添加参考图片（如果有）
        if (this.referImages.length > 0) {
          data.referImages = this.referImages;
        }

        // 只有在 sora-2-pro 模式下才传递 duration 参数
        if (this.model === "sora-2-pro") {
          data.duration = this.duration;
        }

        const res = await vk.callFunction({
          url: "client/sora/pub/generations",
          data: data,
        });

        if (res.code === 0) {
          // 刷新用户积分
          this.loadUserInfo();

          uni.showToast({
            title: "任务创建成功",
            icon: "success",
          });

          // 跳转到详情页
          setTimeout(() => {
            uni.navigateTo({
              url: `/pages/sora/detail?jobId=${res.jobId}`,
            });
          }, 1000);
        } else {
          // 处理积分不足等错误
          if (res.msg && res.msg.includes("积分不足")) {
            const currentIntegral =
              this.userInfo.account_integral?.balance || 0;
            const costIntegral = this.integralCost;
            const needed = costIntegral - currentIntegral;
            const modelName = this.model === "sora-2" ? "标准模式" : "高清模式";
            this.insufficientMessage = `当前积分：${currentIntegral}\n生成视频需要：${costIntegral} 积分 (${modelName})\n还需要：${needed} 积分\n\n立即充值即可获得更多积分`;
            this.showInsufficientDialog = true;
          } else {
            uni.showToast({
              title: res.msg || "创建失败",
              icon: "none",
              duration: 2000,
            });
          }
        }
      } catch (error) {
        console.error("生成视频失败:", error);
        uni.showToast({
          title: "网络错误，请重试",
          icon: "none",
        });
      } finally {
        this.isGenerating = false;
      }
    },

    // 查看作品
    viewWork(work) {
      uni.navigateTo({
        url: `/pages/sora/detail?jobId=${work.jobId}`,
      });
    },

    // 跳转到列表页
    goToList() {
      uni.navigateTo({
        url: "/pages/sora/list",
      });
    },

    // 跳转到积分页
    goToIntegral() {
      uni.navigateTo({
        url: "/pages/user/integral",
      });
    },

    // 跳转到充值页面
    goToRecharge() {
      this.showInsufficientDialog = false;
      uni.navigateTo({
        url: "/pages/user/wallet/wallet",
      });
    },

    // 确认退出登录
    confirmLogout() {
      this.showLogoutDialog = true;
    },

    // 退出登录
    handleLogout() {
      this.showLogoutDialog = false;
      vk.userCenter.logout({
        success: (data) => {
          let { login } = vk.getConfig();
          vk.reLaunch(`${login.url}?change=true`); // 表示切换账号
        },
      });
    },

    // 格式化状态
    formatStatus(status) {
      const map = {
        ON_QUEUE: "生成中",
        SUCCESS: "已完成",
        FAILED: "失败",
      };
      return map[status] || status;
    },

    // 格式化时间
    formatTime(timestamp) {
      const date = new Date(timestamp);
      const now = new Date();
      const diff = now - date;
      const minute = 60 * 1000;
      const hour = 60 * minute;
      const day = 24 * hour;

      if (diff < minute) {
        return "刚刚";
      } else if (diff < hour) {
        return Math.floor(diff / minute) + "分钟前";
      } else if (diff < day) {
        return Math.floor(diff / hour) + "小时前";
      } else {
        return Math.floor(diff / day) + "天前";
      }
    },
  },
};
</script>

<style scoped>
@import url("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css");

page {
  background: #0a0a0a;
}

.sora-container {
  min-height: 100vh;
  background: linear-gradient(180deg, #0a0a0a 0%, #1a1a2e 100%);
  padding-bottom: 40rpx;
}

/* 顶部导航 */
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30rpx 40rpx;
  padding-top: calc(30rpx + constant(safe-area-inset-top));
  padding-top: calc(30rpx + env(safe-area-inset-top));
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(20px);
  border-bottom: 1rpx solid rgba(255, 255, 255, 0.05);
  z-index: 999;
}

.nav-left {
  display: flex;
  align-items: center;
}

.logo-wrapper {
  display: flex;
  align-items: center;
  gap: 16rpx;
}

.logo-icon {
  font-size: 52rpx;
  filter: drop-shadow(0 4rpx 8rpx rgba(139, 92, 246, 0.3));
}

.logo-text-wrapper {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.logo-text {
  font-size: 32rpx;
  font-weight: bold;
  color: #fff;
  letter-spacing: 1rpx;
}

.logo-sub {
  font-size: 24rpx;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 2rpx;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 16rpx;
}

.nav-icon-btn {
  width: 72rpx;
  height: 72rpx;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1rpx solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}

.nav-icon-btn::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(139, 92, 246, 0.2);
  transform: translate(-50%, -50%);
  transition: all 0.3s;
}

.nav-icon-btn:active::before {
  width: 100%;
  height: 100%;
}

.nav-icon-btn .icon {
  font-family: FontAwesome;
  font-size: 32rpx;
  color: rgba(255, 255, 255, 0.9);
  position: relative;
  z-index: 1;
}

.nav-icon-btn.logout {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.2);
}

.nav-icon-btn.logout::before {
  background: rgba(239, 68, 68, 0.2);
}

.nav-icon-btn.logout .icon {
  color: #ef4444;
}

/* 主标题区域 */
.hero-section {
  padding: 60rpx 40rpx;
  padding-top: calc(190rpx + constant(safe-area-inset-top));
  padding-top: calc(190rpx + env(safe-area-inset-top));
  text-align: center;
}

.hero-title {
  margin-bottom: 60rpx;
}

.title-main {
  display: block;
  font-size: 60rpx;
  font-weight: bold;
  color: #fff;
  margin-bottom: 20rpx;
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.title-sub {
  display: block;
  font-size: 32rpx;
  color: rgba(255, 255, 255, 0.6);
}

.hero-stats {
  display: flex;
  justify-content: space-around;
  padding: 40rpx;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 30rpx;
  border: 1rpx solid rgba(255, 255, 255, 0.05);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-number {
  font-size: 48rpx;
  font-weight: bold;
  color: #8b5cf6;
  margin-bottom: 12rpx;
}

.stat-label {
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.5);
}

/* 积分板块 */
.integral-section {
  padding: 0 40rpx 40rpx;
}

.integral-card {
  position: relative;
  overflow: hidden;
  padding: 50rpx 40rpx;
  background: linear-gradient(135deg, #f59e0b 0%, #eab308 50%, #fbbf24 100%);
  border-radius: 30rpx;
  box-shadow: 0 20rpx 60rpx rgba(245, 158, 11, 0.4);
}

.integral-bg-circle {
  position: absolute;
  top: -60rpx;
  right: -60rpx;
  width: 200rpx;
  height: 200rpx;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
}

.integral-bg-circle-2 {
  position: absolute;
  bottom: -40rpx;
  left: -40rpx;
  width: 150rpx;
  height: 150rpx;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
}

.integral-content {
  position: relative;
  display: flex;
  align-items: center;
  gap: 30rpx;
  z-index: 2;
}

.integral-icon-wrapper {
  width: 120rpx;
  height: 120rpx;
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(10px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.15);
}

.integral-icon {
  font-family: FontAwesome;
  font-size: 60rpx;
  color: #fff;
}

.integral-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.integral-label {
  font-size: 28rpx;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 12rpx;
  font-weight: 500;
}

.integral-value {
  font-size: 72rpx;
  font-weight: bold;
  color: #fff;
  line-height: 1;
  margin-bottom: 16rpx;
  text-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
}

.integral-hint {
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.8);
}

.integral-shine {
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.3),
    transparent
  );
  animation: shine 3s infinite;
}

@keyframes shine {
  0% {
    left: -100%;
  }
  50%,
  100% {
    left: 150%;
  }
}

/* 创作区域 */
.create-section {
  padding: 0 40rpx;
}

.section-title {
  display: flex;
  align-items: center;
  margin-bottom: 30rpx;
  font-size: 36rpx;
  font-weight: bold;
  color: #fff;
}

.section-title .icon {
  font-family: FontAwesome;
  margin-right: 16rpx;
  color: #8b5cf6;
}

.section-title .view-all {
  margin-left: auto;
  font-size: 28rpx;
  color: #8b5cf6;
  font-weight: normal;
}

/* Prompt 卡片 */
.prompt-card {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 30rpx;
  padding: 40rpx;
  margin-bottom: 30rpx;
  border: 1rpx solid rgba(255, 255, 255, 0.05);
}

.card-header {
  display: flex;
  align-items: center;
  margin-bottom: 30rpx;
  font-size: 32rpx;
  font-weight: bold;
  color: #fff;
}

.card-header .icon {
  font-family: FontAwesome;
  margin-right: 16rpx;
  color: #8b5cf6;
}

.prompt-input {
  width: 100%;
  min-height: 300rpx;
  padding: 30rpx;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 20rpx;
  border: 1rpx solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 28rpx;
  line-height: 1.6;
}

.prompt-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20rpx;
}

.char-count {
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.4);
}

.quick-prompts {
  display: flex;
  align-items: center;
  padding: 12rpx 24rpx;
  background: rgba(139, 92, 246, 0.1);
  border-radius: 20rpx;
  border: 1rpx solid rgba(139, 92, 246, 0.3);
  font-size: 24rpx;
  color: #8b5cf6;
}

.quick-prompts .icon {
  font-family: FontAwesome;
  margin-right: 8rpx;
}

/* 参考图片 */
.reference-card {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 30rpx;
  padding: 40rpx;
  margin-bottom: 40rpx;
  border: 1rpx solid rgba(255, 255, 255, 0.05);
}

.image-upload-area {
  display: flex;
  flex-wrap: wrap;
  gap: 20rpx;
  margin-bottom: 20rpx;
}

.image-item {
  position: relative;
  width: 200rpx;
  height: 200rpx;
  border-radius: 20rpx;
  overflow: hidden;
}

.preview-image {
  width: 100%;
  height: 100%;
}

.image-delete {
  position: absolute;
  top: 10rpx;
  right: 10rpx;
  width: 50rpx;
  height: 50rpx;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-delete .icon {
  font-family: FontAwesome;
  font-size: 28rpx;
  color: #fff;
}

.image-upload-btn {
  width: 200rpx;
  height: 200rpx;
  border: 2rpx dashed rgba(139, 92, 246, 0.5);
  border-radius: 20rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(139, 92, 246, 0.05);
}

.image-upload-btn .icon {
  font-family: FontAwesome;
  font-size: 48rpx;
  color: #8b5cf6;
  margin-bottom: 12rpx;
}

.upload-text {
  font-size: 24rpx;
  color: #8b5cf6;
}

.image-tips {
  display: flex;
  align-items: center;
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.4);
}

.image-tips .icon {
  font-family: FontAwesome;
  margin-right: 8rpx;
  color: #ec4899;
}

/* 生成设置 */
.options-card {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 30rpx;
  padding: 40rpx;
  margin-bottom: 40rpx;
  border: 1rpx solid rgba(255, 255, 255, 0.05);
}

.option-group {
  margin-bottom: 40rpx;
}

.option-group:last-child {
  margin-bottom: 0;
}

.option-label {
  display: flex;
  flex-direction: column;
  margin-bottom: 20rpx;
}

.label-text {
  font-size: 28rpx;
  font-weight: bold;
  color: #fff;
  margin-bottom: 8rpx;
}

.label-desc {
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.5);
}

.option-buttons {
  display: flex;
  gap: 20rpx;
}

.option-btn {
  flex: 1;
  height: 90rpx;
  background: rgba(0, 0, 0, 0.3);
  border: 2rpx solid rgba(255, 255, 255, 0.1);
  border-radius: 20rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 26rpx;
  color: rgba(255, 255, 255, 0.6);
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}

.option-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  opacity: 0;
  transition: opacity 0.3s;
}

.option-btn.active {
  border-color: #8b5cf6;
  color: #fff;
  box-shadow: 0 8rpx 24rpx rgba(139, 92, 246, 0.3);
}

.option-btn.active::before {
  opacity: 0.15;
}

.option-btn .btn-icon {
  font-family: FontAwesome;
  font-size: 32rpx;
  margin-bottom: 8rpx;
  position: relative;
  z-index: 1;
}

.option-btn text:last-child {
  position: relative;
  z-index: 1;
}

.option-tips {
  display: flex;
  align-items: flex-start;
  gap: 8rpx;
  padding: 20rpx;
  background: rgba(236, 72, 153, 0.08);
  border-radius: 16rpx;
  border: 1rpx solid rgba(236, 72, 153, 0.2);
  margin-top: 20rpx;
}

.option-tips .icon {
  font-family: FontAwesome;
  font-size: 24rpx;
  color: #ec4899;
  margin-top: 2rpx;
}

.option-tips text:last-child {
  flex: 1;
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.6);
  line-height: 1.5;
}

/* 生成按钮 */
.generate-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 60rpx;
}

.generate-btn {
  width: 100%;
  height: 100rpx;
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  border-radius: 50rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32rpx;
  font-weight: bold;
  color: #fff;
  border: none;
  box-shadow: 0 10rpx 40rpx rgba(139, 92, 246, 0.4);
  transition: all 0.3s;
}

.generate-btn.disabled {
  opacity: 0.5;
  box-shadow: none;
}

.generate-btn .btn-icon {
  font-family: FontAwesome;
  margin-right: 16rpx;
  font-size: 36rpx;
}

.generate-tips-wrapper {
  display: flex;
  align-items: center;
  gap: 30rpx;
  margin-top: 20rpx;
}

.generate-tips {
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.4);
}

.integral-cost-tip {
  display: flex;
  align-items: center;
  gap: 8rpx;
  padding: 8rpx 20rpx;
  background: linear-gradient(
    135deg,
    rgba(245, 158, 11, 0.2) 0%,
    rgba(251, 191, 36, 0.2) 100%
  );
  border-radius: 20rpx;
  border: 1rpx solid rgba(245, 158, 11, 0.4);
  font-size: 24rpx;
  color: #fbbf24;
  font-weight: 500;
}

.integral-cost-tip .icon {
  font-family: FontAwesome;
  font-size: 24rpx;
  color: #f59e0b;
}

/* 最近作品 */
.recent-section {
  padding: 60rpx 40rpx;
}

.recent-scroll {
  white-space: nowrap;
  margin-top: 30rpx;
}

.work-card {
  display: inline-block;
  width: 300rpx;
  margin-right: 30rpx;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 20rpx;
  overflow: hidden;
  border: 1rpx solid rgba(255, 255, 255, 0.05);
}

.work-cover {
  position: relative;
  width: 100%;
  height: 300rpx;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.work-cover image {
  width: 100%;
  height: 100%;
}

.work-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.work-placeholder .icon {
  font-family: FontAwesome;
  font-size: 60rpx;
  color: #8b5cf6;
}

.work-status {
  position: absolute;
  top: 20rpx;
  right: 20rpx;
  padding: 8rpx 20rpx;
  border-radius: 20rpx;
  font-size: 20rpx;
  color: #fff;
  backdrop-filter: blur(10px);
}

.work-status.on_queue {
  background: rgba(251, 191, 36, 0.8);
}

.work-status.success {
  background: rgba(34, 197, 94, 0.8);
}

.work-status.failed {
  background: rgba(239, 68, 68, 0.8);
}

.work-info {
  padding: 20rpx;
}

.work-prompt {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.8);
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.5;
  margin-bottom: 12rpx;
  word-break: break-all;
}

.work-time {
  display: block;
  font-size: 20rpx;
  color: rgba(255, 255, 255, 0.4);
}

/* 积分不足提示对话框 */
.alert-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
  animation: fadeIn 0.3s;
}

.alert-dialog {
  width: 560rpx;
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
  border-radius: 30rpx;
  padding: 60rpx 40rpx 40rpx;
  border: 1rpx solid rgba(239, 68, 68, 0.4);
  box-shadow: 0 20rpx 60rpx rgba(239, 68, 68, 0.3);
  animation: slideUp 0.3s;
}

.alert-icon-wrapper {
  position: relative;
  width: 120rpx;
  height: 120rpx;
  margin: 0 auto 30rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.alert-icon-wrapper.error .alert-icon-bg {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  animation: pulse 2s infinite;
}

.alert-icon-bg {
  position: absolute;
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
  opacity: 0.2;
}

.alert-icon {
  position: relative;
  font-family: FontAwesome;
  font-size: 56rpx;
  color: #ef4444;
  z-index: 2;
}

.alert-title {
  display: block;
  text-align: center;
  font-size: 36rpx;
  font-weight: bold;
  color: #fff;
  margin-bottom: 30rpx;
}

.alert-message {
  display: block;
  text-align: center;
  font-size: 28rpx;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.6;
  margin-bottom: 40rpx;
  white-space: pre-line;
}

.alert-actions {
  display: flex;
  gap: 20rpx;
}

.alert-btn {
  flex: 1;
  height: 90rpx;
  border-radius: 50rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30rpx;
  font-weight: 500;
  border: none;
  transition: all 0.3s;
}

.alert-btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  border: 1rpx solid rgba(255, 255, 255, 0.1);
}

.alert-btn.secondary:active {
  background: rgba(255, 255, 255, 0.12);
}

.alert-btn.primary {
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  color: #fff;
  box-shadow: 0 8rpx 24rpx rgba(139, 92, 246, 0.4);
}

.alert-btn.primary:active {
  transform: scale(0.98);
}

.alert-btn .btn-icon {
  font-family: FontAwesome;
  margin-right: 12rpx;
  font-size: 28rpx;
}

/* 生成确认对话框 */
.confirm-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s;
}

.confirm-dialog {
  width: 600rpx;
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
  border-radius: 30rpx;
  padding: 50rpx 40rpx 40rpx;
  border: 1rpx solid rgba(139, 92, 246, 0.3);
  box-shadow: 0 20rpx 60rpx rgba(0, 0, 0, 0.5);
  animation: slideUp 0.3s;
}

.confirm-icon-wrapper {
  position: relative;
  width: 120rpx;
  height: 120rpx;
  margin: 0 auto 30rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.confirm-icon-bg {
  position: absolute;
  width: 120rpx;
  height: 120rpx;
  background: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);
  border-radius: 50%;
  opacity: 0.2;
  animation: pulse 2s infinite;
}

.confirm-icon {
  position: relative;
  font-family: FontAwesome;
  font-size: 60rpx;
  color: #fbbf24;
  z-index: 2;
}

.confirm-title {
  display: block;
  text-align: center;
  font-size: 36rpx;
  font-weight: bold;
  color: #fff;
  margin-bottom: 40rpx;
}

.confirm-content {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 20rpx;
  padding: 30rpx;
  margin-bottom: 40rpx;
  border: 1rpx solid rgba(255, 255, 255, 0.05);
}

.integral-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx 0;
}

.integral-info-row.remain {
  border-top: 2rpx dashed rgba(255, 255, 255, 0.1);
  margin-top: 15rpx;
  padding-top: 25rpx;
}

.info-label {
  font-size: 28rpx;
  color: rgba(255, 255, 255, 0.7);
}

.info-value {
  font-size: 40rpx;
  font-weight: bold;
  color: #fff;
}

.info-value.current {
  color: #8b5cf6;
}

.info-value.cost {
  color: #ef4444;
}

.integral-divider {
  text-align: center;
  padding: 10rpx 0;
}

.divider-icon {
  font-family: FontAwesome;
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.3);
}

.confirm-actions {
  display: flex;
  gap: 20rpx;
}

.confirm-btn {
  flex: 1;
  height: 90rpx;
  border-radius: 50rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30rpx;
  font-weight: 500;
  border: none;
}

.confirm-btn.cancel {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  border: 1rpx solid rgba(255, 255, 255, 0.1);
}

.confirm-btn.confirm {
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  color: #fff;
  box-shadow: 0 8rpx 24rpx rgba(139, 92, 246, 0.4);
}

.confirm-btn .btn-icon {
  font-family: FontAwesome;
  margin-right: 12rpx;
  font-size: 28rpx;
}

/* 退出登录对话框样式 */
.logout-dialog {
  border-color: rgba(239, 68, 68, 0.3);
}

.logout-bg {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

.logout-icon {
  color: #ef4444;
}

.logout-message {
  display: block;
  text-align: center;
  font-size: 28rpx;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.6;
  margin-bottom: 40rpx;
}

.logout-confirm {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  box-shadow: 0 8rpx 24rpx rgba(239, 68, 68, 0.4);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(100rpx);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.2;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.3;
  }
}

/* 模板弹窗 */
.template-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: flex-end;
  z-index: 999;
}

.modal-content {
  width: 100%;
  max-height: 80vh;
  background: #1a1a2e;
  border-radius: 40rpx 40rpx 0 0;
  padding: 40rpx;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30rpx;
}

.modal-title {
  font-size: 36rpx;
  font-weight: bold;
  color: #fff;
}

.modal-close {
  font-family: FontAwesome;
  font-size: 40rpx;
  color: rgba(255, 255, 255, 0.6);
}

.template-list {
  max-height: 60vh;
}

.template-item {
  display: flex;
  align-items: flex-start;
  padding: 30rpx;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 20rpx;
  margin-bottom: 20rpx;
  border: 1rpx solid rgba(255, 255, 255, 0.05);
}

.template-icon {
  font-size: 60rpx;
  margin-right: 20rpx;
}

.template-info {
  flex: 1;
}

.template-name {
  display: block;
  font-size: 28rpx;
  font-weight: bold;
  color: #fff;
  margin-bottom: 12rpx;
}

.template-desc {
  display: block;
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.6);
  line-height: 1.6;
}

/* 动画 */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.spinning {
  animation: spin 1s linear infinite;
}
</style>
